﻿using System;
using System.Linq;
using System.Web.UI;
using FranceTriple.Dal;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace TeamFranceTriple
{
    public partial class UserPanel : BaseUserControl
    {
        private HyperLink HeadLoginStatusLink, ChangePasswordLink;
        private LoginStatus HeadLoginStatus;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            Gravatar1.Email = ThisMaster.Requester.Profile.UserGravatarEmail;
            UserInfoPanel.Visible = ThisMaster.Requester.IsAuthenticated;
            AwaitingUserHyperLink.Enabled = ThisMaster.Requester.Roles.Contains("RoleAdminForum");

            UserProfile1.NavigateUrl = "~/" + ThisMaster.Requester.Culture + "/userprofile";

            HeadLoginStatusLink = (HyperLink)(HeadLoginView.FindControl("HeadLoginStatusLink"));
            if (HeadLoginStatusLink != null)
                HeadLoginStatusLink.NavigateUrl = "~/" + ThisMaster.Requester.Culture + "/connexion/?returnurl=" + this.Page.Request.RawUrl;

            ChangePasswordLink = (HyperLink)(HeadLoginView.FindControl("ChangePasswordLink"));
            if (ChangePasswordLink != null)
                ChangePasswordLink.NavigateUrl = "~/" + ThisMaster.Requester.Culture + "/userprofile";

            HeadLoginStatus = (LoginStatus)(HeadLoginView.FindControl("HeadLoginStatus"));
            if (HeadLoginStatus != null)
                HeadLoginStatus.LogoutPageUrl = "~/" + ThisMaster.Requester.Culture + "/logout";

            HyperLink1.NavigateUrl = "~/" + ThisMaster.Requester.Culture + "/userprofile";
            AwaitingUserHyperLink.NavigateUrl = "~/" + ThisMaster.Requester.Culture + "/awaitingusers";

            if (ThisMaster.Requester.Membership != null)
            {
                Label3.Text = DateTime.Parse(ThisMaster.Requester.Membership.CreationDate.ToUniversalTime().ToUserTimeZone(ThisMaster.Requester.Profile.TimeZone).ToString()).ToString();
                Label5.Text = DateTime.Parse(ThisMaster.Requester.Membership.LastActivityDate.ToUniversalTime().ToUserTimeZone(ThisMaster.Requester.Profile.TimeZone).ToString()).ToString();
            }
        }
    }
}